# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
  
  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
  filter_parameter_logging :fb_sig_friends, :password
  
  helper_method :facebook_session,:facebook_session_secured?, :facebook_user, :user_session, :has_session?
  # Scrub sensitive parameters from your log
  #filter_parameter_logging :password
  
  ###########################
  # Ensure is authenticated
  ##########################
  def ensure_authenticated
    if !has_session?
      raise Webapp::NotAuthenticated
    end
  end
  
  def facebook_session_secured?
    return (facebook_session and facebook_session.secured?)
  end
  
  def facebook_user
    fb_user = nil
    if facebook_session_secured?
      fb_user = facebook_session.user 
    end
    fb_user
    
  end
  
  def user_session
    session[:user_session]
  end
  def has_session?
    return true if session[:user_session]
    false
  end
end
